package logic

import (
	"context"
	"errors"
	"go.uber.org/zap"
	"homepage_srv/homepage"
	"homepage_srv/internal/dao"
	"homepage_srv/internal/svc"
	"smart-health-platforms/pkg"

	"github.com/zeromicro/go-zero/core/logx"
)

type GoodShopLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewGoodShopLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GoodShopLogic {
	return &GoodShopLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

// 查询商铺店铺信息
func (l *GoodShopLogic) GoodShop(in *homepage.GoodShopRequest) (*homepage.GoodShopResponse, error) {
	shopDate, err := dao.GoodShop(in)
	if err != nil {
		pkg.Error("店铺信息查询失败: %s", zap.Error(err))
		return nil, errors.New("店铺信息查询失败")
	}
	pkg.Info("店铺信息查询成功")
	return &homepage.GoodShopResponse{
		ShopId:          uint64(shopDate.Id),
		BrandId:         uint64(shopDate.BrandId),
		ShopName:        shopDate.ShopName,
		ShopImage:       shopDate.ShopImage,
		ShopAddress:     shopDate.ShopAddress,
		ShopDescription: shopDate.ShopDescription,
		ShopPhone:       shopDate.ShopPhone,
		ShopEmail:       shopDate.ShopEmail,
		MonthSales:      uint64(shopDate.MonthSales),
		Status:          uint64(shopDate.Status),
	}, nil
}
